<?php
//uu_qunar_use 需要添加tid字段，然后添加数据的时候那边添加上tid，更新表的tid字段，最后根据tid来获取数据，判别往去哪儿还是美团通知
if (!class_exists("go_sql")){
	include("/var/www/html/new/conf/le.je");
	$le=new go_sql();
	$le->connect();
}
$txt=json_encode($_REQUEST);
logfile($txt);

$action = $_REQUEST['action']; //操作类型：SetProdStatus：1上架，2下架  CreateNewTicket：修改
if($action){
	if($action == 'CreateNewTicket') $status=2;  // 0,下架 1,上架 2,修改
	elseif($action == 'SetProdStatus' && $_REQUEST['status'] == 1) $status = 1;
	elseif($action == 'SetProdStatus' && $_REQUEST['status'] == 2) $status = 0;

	$tid = $_REQUEST['tid'];
	if($tid){
		$selids = "select tid_aid,DockingMode from uu_qunar_use where tid=$tid";
		$GLOBALS['le']->query($selids);
		while($row=$GLOBALS['le']->fetch_assoc()) 
			$Orders[] = $row;
		if($Orders){
			foreach($Orders as $arr){ 
				$tid_aid = $arr['tid_aid'];
				if($arr['DockingMode'] == 0){ //去哪儿
					file_get_contents("http://coop.12301.cc/callback/ProductChangeNotice.php?ids=$tid_aid&status=$status");
				}elseif($arr['DockingMode'] == 1){ //美团
					file_get_contents("http://www.12301.cc/meituan/MT_ChangeNotice.php?ids=$tid_aid&status=$status");
				} 
			}
		}
	}
}

function logfile($word){
	$path = 'api_product_changenotice';
	$filepath= '/var/www/html/new/d/logs/api/ChangYouTong/'.$path.'.txt';
	$word = date("Y-m-d H:i:s")."|".$word;
	if(file_exists($filepath)){			
		$maxsize  = 1024*1024*10;
		$filesize = filesize($filepath);
		$filetype = end(explode(".",$filepath));
		$filename = substr($filepath,0,strpos($filepath,'.'));
		if($filesize>$maxsize)
			rename($filepath, $filename.'_'.date('YmdHis').'.'.$filetype);
	}
	$fp = fopen($filepath,"a");
	flock($fp, LOCK_EX);
	fwrite($fp,$word."\n");
	flock($fp, LOCK_UN);
	fclose($fp);
}
?>
p);
}
?>
